package com.weiyuwqj.admin.controller.admin.sys;

import com.weiyuwqj.api.service.SysNoticeTypeService;
import com.weiyuwqj.api.common.Paginator;
import com.weiyuwqj.api.model.SysNoticeType;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value="/admin/sysNoticeType")
public class SysNoticeTypeController {

    @Autowired
    SysNoticeTypeService sysNoticeTypeService;

    @ResponseBody
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public  Object list(@ModelAttribute Paginator p, HttpServletRequest request){
        String nid = request.getParameter("nid");
        String noticeType = request.getParameter("noticeType");
        String type = request.getParameter("type");
        String status = request.getParameter("status");
        String beginDateTime = request.getParameter("beginDateTime");
        String endDateTime = request.getParameter("endDateTime");
        String orderName= request.getParameter("orderName");
        String orderWay = request.getParameter("orderWay");
        Map<String,Object> map=new HashMap<String,Object>();
        if(StringUtils.isNotEmpty(nid)){
            map.put("nid", nid);
        }
        if(StringUtils.isNotEmpty(noticeType)){
            map.put("noticeType", noticeType);
        }
        if(StringUtils.isNotEmpty(type)){
            map.put("type", type);
        }
        if(StringUtils.isNotEmpty(status)){
            map.put("status", status);
        }
        if(StringUtils.isNotEmpty(beginDateTime)){
            map.put("beginDateTime", beginDateTime);
        }
        if(StringUtils.isNotEmpty(endDateTime)){
            map.put("endDateTime", endDateTime);
        }
        if(StringUtils.isNotEmpty(orderName)){
            map.put("orderName", orderName);
        }
        if(StringUtils.isNotEmpty(orderWay)){
            map.put("orderWay", orderWay);
        }
        return sysNoticeTypeService.getList(p, map);
    }

    //新建模板
    @ResponseBody
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public void add(SysNoticeType noticeType){
        sysNoticeTypeService.save(noticeType);
    }

    //获取编辑信息
    @ResponseBody
    @RequestMapping(value="/getSingle",method = RequestMethod.POST)
    public Object getSingle(Integer id) {
        return sysNoticeTypeService.getSingle(id);
    }

    //编辑
    @ResponseBody
    @RequestMapping(value="/edit",method = RequestMethod.POST)
    public Object edit(SysNoticeType sysNoticeType) {
        return sysNoticeTypeService.updateNotNull(sysNoticeType);
    }

    //删除
    @ResponseBody
    @RequestMapping(value="/del",method = RequestMethod.POST)
    public void del(SysNoticeType noticeType){
        sysNoticeTypeService.delete(noticeType);
    }

    //启用禁用
   @RequestMapping(value = "/enableToggle", method = RequestMethod.POST)
   public void enableToggle(int noticeId){
	   sysNoticeTypeService.enableToggle(noticeId);
   }

    //获取编辑信息
    @ResponseBody
    @RequestMapping(value="/getNoticeTypeByNid",method = RequestMethod.POST)
    public Object getNoticeTypeByNid(@RequestParam(defaultValue = "") String nid) {
        return sysNoticeTypeService.getNoticeTypeByNid(nid);
    }

}
